<?php
namespace ShopApi\Controller;
use Zend\Mvc\Controller\AbstractRestfulController;
use Zend\View\Model\JsonModel;
class ShopComplaintsApiController extends AbstractRestfulController
{
    public function getList()
    {			
			
    }
    public function get($shop_id)
    {			
		header('Access-Control-Allow-Origin: *');	
		$complaintsTable=$this->getServiceLocator()->get('Models\Model\ComplaintsFactory');
		$getShopComplaints = $complaintsTable->getShopComplaints($shop_id)->toarray();
		if(count($getShopComplaints)!=0){
			return new JsonModel(array(
				'output' 	=> 'success',
				'data' 		=> json_encode($getShopComplaints),
			));
		}else{
			return new JsonModel(array(
				'output' => 'fail',
			));
		}	
    }
    public function create($data)
    {
		
    }
    public function update($complaint_id,$data)
    {
		header('Access-Control-Allow-Origin: *');
		$complaintRelpiesTable=$this->getServiceLocator()->get('Models\Model\ComplaintRelpiesFactory');
		if($data['complaint_relpies_id']==0){
			$addReplyToComplaints = $complaintRelpiesTable->addReplyToComplaints($complaint_id,$data);
			if($addReplyToComplaints!=0){
				return new JsonModel(array(
					'output' 	=> 'success',
					'Reply Id' 	=> $addReplyToComplaints,
				));
			}else{
				return new JsonModel(array(
					'output' => 'fail',
				));
			}
		}else{
			$updateReplyOfComplaints = $complaintRelpiesTable->updateReplyOfComplaints($data);
			if($updateReplyOfComplaints){
				return new JsonModel(array(
					'output' 	=> 'success',
				));
			}else{
				return new JsonModel(array(
					'output' => 'fail',
				));
			}
		}	
    }
    public function delete($id)
    {
       
    }
}